package list;

import java.util.Scanner;

/**
 * Author:大鱼
 * gitee:https://gitee.com/TheInit/leetcode
 * leetcode 82删除排序链表中的重复元素
 */
public class DeleteDuplicates {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        String[] split = s.substring(1, s.length() - 1).split(",");

        int[] nums = new int[split.length];
        for (int i = 0; i < nums.length; i++) {
            nums[i] = Integer.parseInt(split[i]);
        }
        ListNode head = ListUtil.getListFromArray(nums);
        deleteDuplicates(head);
        ListUtil.listToString(head);
    }

    public static ListNode deleteDuplicates(ListNode head) {
        ListNode pre = new ListNode();
        pre.next = head;
        ListNode cur = pre;
        while (cur.next != null && cur.next.next != null) {
            if (cur.next.val == cur.next.next.val) {
                int deleteV = cur.next.val;
                while (cur.next != null && cur.next.val == deleteV) {
                    cur.next = cur.next.next;
                }
            } else {
                cur = cur.next;
            }
        }
        return pre.next;
    }
}
